<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-steps
      :align-center="true"
      :space="800"
      :active="active"
      finish-status="success"
    >
      <el-step title="确认信息"></el-step>
      <el-step title="付款"></el-step>
      <el-step title="付款成功"></el-step>
    </el-steps>

    <el-descriptions
      v-if="active == 1"
      class="margin-top"
      title="确认信息"
      :column="3"
      :size="size"
      border
    >
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-user"></i>
          宿舍号
        </template>
        {{ this.dataForm.dormId }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-mobile-phone"></i>
          月份
        </template>
        {{ this.dataForm.month }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-location-outline"></i>
          水电费总计
        </template>
        {{ this.dataForm.sum }} 元
      </el-descriptions-item>
      <!-- <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-tickets"></i>
          备注
        </template>
        <el-tag size="small">学校</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-office-building"></i>
          联系地址
        </template>
        江苏省苏州市吴中区吴中大道 1188 号
      </el-descriptions-item> -->
    </el-descriptions>
    <el-image
      v-if="active == 2"
      style="width: 250px; height: 250px;"
      :fit="fit"
      :src="url"
    ></el-image>
    <!-- <img v-if="active==2" :src="url" width="250px" height="250px"> -->
    <span v-if="active == 2" style="text-align: center"
      ><h1>
        立即缴费：<span style="color: red">{{ this.dataForm.sum }}</span> ￥
      </h1></span
    >

    <el-result
      v-if="active == 3"
      icon="success"
      title="缴费成功"
      subTitle="请根据提示进行操作"
    >
      <template slot="extra">
        <el-button type="primary" size="medium" @click="nextStep()"
          >返回</el-button
        >
      </template>
    </el-result>

    <span slot="footer" class="dialog-footer">
      <el-button
        v-if="active != 3"
        @click="
          visible = false;
          active = 1;
        "
        >取消</el-button
      >
      <el-button v-if="active != 3" type="primary" @click="nextStep()"
        >下一步</el-button
      >
      <!-- <el-button v-if="active == 3" type="primary" @click="nextStep()"
        >ok</el-button
      > -->
    </span>
  </el-dialog>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        waterFare: "",
        etcFare: "",
        sum: "",
        waterCount: "",
        etcCount: "",
        waterPrice: "",
        etcPrice: "",
        dormId: "",
        month: "",
        status: "",
        createTime: "",
      },
      active: 1,
      size: "",
      fits: ["fill", "contain", "cover", "none", "scale-down"],
      url: "https://gulimall-lemonx.oss-cn-shenzhen.aliyuncs.com/2022-10-27/4a54a8b1-2284-4da2-8209-31b631b74038_%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20221027200746.jpg",

      dataRule: {
        waterFare: [
          { required: true, message: "水费不能为空", trigger: "blur" },
        ],
        etcFare: [{ required: true, message: "电费不能为空", trigger: "blur" }],
        sum: [{ required: true, message: "总计不能为空", trigger: "blur" }],
        waterCount: [
          { required: true, message: "用水量(L)不能为空", trigger: "blur" },
        ],
        etcCount: [
          { required: true, message: "用电量（度）不能为空", trigger: "blur" },
        ],
        waterPrice: [
          { required: true, message: "水费单价不能为空", trigger: "blur" },
        ],
        etcPrice: [
          { required: true, message: "电费单价不能为空", trigger: "blur" },
        ],
        dormId: [
          { required: true, message: "宿舍id不能为空", trigger: "blur" },
        ],
        month: [{ required: true, message: "年_月不能为空", trigger: "blur" }],
        status: [
          {
            required: true,
            message: "缴费状态（0:未交 1：已交）不能为空",
            trigger: "blur",
          },
        ],
        // createTime: [
        //   { required: true, message: '创建时间不能为空', trigger: 'blur' }
        // ]
      },
    };
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        // this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/sys/dormfare/info/${this.dataForm.id}`),
            method: "get",
            params: this.$http.adornParams(),
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.waterFare = data.dormFare.waterFare;
              this.dataForm.etcFare = data.dormFare.etcFare;
              this.dataForm.sum = data.dormFare.sum;
              this.dataForm.waterCount = data.dormFare.waterCount;
              this.dataForm.etcCount = data.dormFare.etcCount;
              this.dataForm.waterPrice = data.dormFare.waterPrice;
              this.dataForm.etcPrice = data.dormFare.etcPrice;
              this.dataForm.dormId = data.dormFare.dormId;
              this.dataForm.month = data.dormFare.month;
              this.dataForm.status = data.dormFare.status;
              this.dataForm.createTime = data.dormFare.createTime;
            }
          });
        }
      });
    },
    nextStep() {
      this.active++;
      if (this.active == 4) {
        this.visible = false;
        this.$emit("refreshDataList");
        this.active = 1;
      } else if (this.active == 3) {
        this.$http({
          url: this.$http.adornUrl(`/sys/dormfare/pay/${this.dataForm.id}`),
          method: "get",
          // params: this.$http.adornParams(),
        }).then(({ data }) => {
          if (data && data.code === 0) {
             
          }
        });
      }
    },

    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(
              `/sys/dormfare/${!this.dataForm.id ? "save" : "update"}`
            ),
            method: "post",
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              waterFare: this.dataForm.waterFare,
              etcFare: this.dataForm.etcFare,
              sum: this.dataForm.sum,
              waterCount: this.dataForm.waterCount,
              etcCount: this.dataForm.etcCount,
              waterPrice: this.dataForm.waterPrice,
              etcPrice: this.dataForm.etcPrice,
              dormId: this.dataForm.dormId,
              month: this.dataForm.month,
              status: this.dataForm.status,
              createTime: this.dataForm.createTime,
            }),
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                },
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    },
  },
};
</script>
<style scoped lang='scss'>
/deep/.el-descriptions {
  margin-top: 100px !important;
  margin-bottom: 100px !important;
}
/deep/.el-image {
  // margin-top: 100px !important;
  // margin-bottom: 100px !important;
  display: block;
  margin: 50px auto 50px !important;
  // display: flex;
  // justify-content: center;

  // vertical-align: middle !important;
  // align-self: center;
  // text-align: center !important;
  // margin: auto !important;
}
>>> .el-image__inner {
  // margin: 200px auto !important;

}
</style>
